from rest_framework import serializers
from apps.app01.models import User


class UserUpdateSerializer(serializers.ModelSerializer):
    class Meta:
        model = User
        fields = ['nickname', 'gender']

    def validate_gender(self, value):
        # 确保性别在有效选项中
        if value not in [0, 1, 2]:
            raise serializers.ValidationError("Invalid gender value.")
        return value